package com.eastidea.live.util;

import java.util.Random;

import org.apache.commons.lang3.StringUtils;

public class StringUtil extends StringUtils {
	private static Random randGen = null;
	private static char[] numbersAndLetters = null;
	private static Object initLock = new Object();

	
	public static boolean IsEmpty(String s) {
		if (s == null) {
			return true;
		}
		s = s.trim();
		if (s.equals("")) {
			return true;
		}
		return false;
	}
	
	public static String GetNumString(String s, Integer m) {
		if (s.length() < m) {
			for (int i = 0; i < m - s.length(); i++)
				s = "0" + s;
		}
		return s;
	}

	public static final String RandomString(int length) {
		if (length < 1) {
			return null;
		}
		if (randGen == null) {
			synchronized (initLock) {
				if (randGen == null) {
					randGen = new Random();
					numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
							.toCharArray();
					// numbersAndLetters =
					// ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
				}
			}
		}
		char[] randBuffer = new char[length];
		for (int i = 0; i < randBuffer.length; i++) {
			randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
			// randBuffer[i] = numbersAndLetters[randGen.nextInt(35)];
		}
		return new String(randBuffer);
	}
}
